#include<bits/stdc++.h>

using namespace std;

int n;
int a[200005];
int vis[200005];

int dfs(int d,int col)
{
    if(d>n)
        return 0;
    vis[d]=col;
    int c=0;
    for(int j=d-1;j>=1;j--)
    {
        if(vis[j]==vis[d])
        {
            if(a[j]==a[d])
                c=a[d];
            break;
        }
    }
    return max(dfs(d+1,1),dfs(d+1,0))+c;
}

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    for(int k=0;k<T;k++)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        memset(vis,-1,sizeof(vis));
        cout<<max(dfs(1,0),dfs(1,1))<<endl;
    }
    return 0;
}
